#ifndef _INPUTS_MANAGER_H_
#define _INPUTS_MANAGER_H_

#include "cocos2d.h"

using namespace cocos2d;

class Key
{
public:
	bool Pressed;
	bool Press;
	bool Released;

	int FrameSameState;
};

class TouchArea
{
public:
	CCTouch* Id;
	
	CCPoint Start;
	CCPoint End;

	TouchArea()
	{
		Id = NULL;
		Start = CCPoint(0.0f, 0.0f);
		End = CCPoint(0.0f, 0.0f);
	}

	TouchArea(CCTouch* _id, CCPoint _start)
	{
		Id = _id;
		Start = _start;
		End =_start;
	}
};

#define MAX_TOUCH_AREA 5

class CustomButton;

class InputsManager : public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
{
public:
	enum KEY
	{
		KEY_JUMP = 0,
		KEY_LEFT,
		KEY_RIGHT,
		KEY_RUN,

		KEY_COUNT
	};

private:

	Key KeyList[KEY_COUNT];
	int Keyid[KEY_COUNT];
	CustomButton* VirtualKeyList[KEY_COUNT];

	TouchArea ListTouchArea[MAX_TOUCH_AREA];

	// construtor
	InputsManager();
public:

	virtual ~InputsManager(){}

	static InputsManager* GetInstance();
	void update(ccTime dt);
	void draw();

	Key GetKeyState( int KEY_ID ) { return KeyList[KEY_ID];}
    
	void SetVirtualKey( int Key_Id, CustomButton* _virtualKey );
    void SetKeyPress( int Key_Id, bool isPress );

	void CreateVirtualKey( CCNode* Parent );
	void DeleteVirtualKey( );

	void RefreshVirtualKey();

public: // delegate

	virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
	virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
	virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event);
	virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
    

    virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
 	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
 	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
 	virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent);
};

#define INPUTS InputsManager::GetInstance()
#define KEY_ID InputsManager

#endif